//
//  JHSVideoPlayerItem.swift
//  JHSVideo
//
//  Created by 阿飞 on 2020/12/25.
//

import Foundation
import AVFoundation

public class JHSVideoPlayerResource {
    public let name: String
    public let cover: URL?
    public var subtitle: JHSVideoSubtitles?
    public let definitions: [JHSVideoPlayerResourceDefinition]
   
    public convenience init(url: URL, name: String = "", cover: URL? = nil, subtitle: URL? = nil) {
        let definition = JHSVideoPlayerResourceDefinition(url: url, definition: "")
        
        var subtitles: JHSVideoSubtitles? = nil
        if let subtitle = subtitle {
            subtitles = JHSVideoSubtitles(url: subtitle)
        }
        
        self.init(name: name, definitions: [definition], cover: cover, subtitles: subtitles)
    }
    
   
    public init(name: String = "", definitions: [JHSVideoPlayerResourceDefinition], cover: URL? = nil, subtitles: JHSVideoSubtitles? = nil) {
        self.name        = name
        self.cover       = cover
        self.subtitle    = subtitles
        self.definitions = definitions
    }
}


open class JHSVideoPlayerResourceDefinition {
    public let url: URL
    public let definition: String
    
    public var options: [String : Any]?
    
    open var avURLAsset: AVURLAsset {
        get {
            return JHSVideoPlayerManager.asset(for: self)
        }
    }
    
    
    public init(url: URL, definition: String, options: [String : Any]? = nil) {
        self.url        = url
        self.definition = definition
        self.options    = options
    }
}
